--[[
  ** 关于生成工具的声明 **

  ** 关于技能的信息 **
--]]

local _skill_val = fk.CreateSkill {
  name = "steam__youlongxifeng",
  tags = {},
}

Fk:loadTranslationTable {
  ["steam__youlongxifeng"] = "游龙戏凤",
  ["#steam__youlongxifeng"] = "游龙戏凤：请选择要被移动的角色",
  [":steam__youlongxifeng"] = "你可将场上的“将军抽车”移向一名角色以向其发动“慷忾”。你“将军抽车”数量变动过的回合结束时，你可令一名角色视为使用【杀】。",
  ["ylxf__removeequip"] = "移动装备",
  ["ylxf__removeskill"] = "移动技能",
  ["#steam__youlongxifeng-invoke"]="请选择要移动的将军抽车",
  ["#steam__youlongxifeng-chooseget"]="请选择移向的角色",
  ["#steam__kangkai-useslash"]="令一名角色视为使用杀",
}

local changeskill=function (room, player, isget)
  if isget then
    room:handleAddLoseSkills(player,"steam__jiangjunchoujun")
  else
    room:handleAddLoseSkills(player,"-steam__jiangjunchoujun")
  end
  room:addPlayerMark(player,"steam__jjcj-turn")
end




_skill_val:addEffect('active', {
  prompt="#steam__youlongxifeng",
  target_num=1,
  card_num=0,
  target_filter=function (self, player, to_select, selected, selected_cards, card, extra_data)
    if #selected>0 then
      return false
    end
    return to_select:hasSkill("steam__jiangjunchoujun")
  end,
  on_use =function (self, room, skillUseEvent)
    local player=skillUseEvent.from
    local target=skillUseEvent.tos[1]
    local choices={}
    if table.find(player:getCardIds("ej"), function (id)
      return Fk:getCardById(id):getMark("steam__jiangjunchoujun")~=0
    end) then
      table.insert(choices, "ylxf__removeequip")
    end
    if table.contains(Fk.generals[player.general]:getSkillNameList(), "steam__jiangjunchoujun") and player:hasSkill("steam__jiangjunchoujun") then
      table.insert(choices, "ylxf__removeskill")

    elseif player.deputyGeneral and table.contains(Fk.generals[player.deputyGeneral]:getSkillNameList(),"steam__jiangjunchoujun") and player:hasSkill("steam__jiangjunchoujun") then
      table.insert(choices, "ylxf__removeskill")

    end
    local choice = room:askForChoice(player, choices, "steam__youlongxifeng","#steam__youlongxifeng-invoke")
    local tars=self.youlingxifeng_tos or room.alive_players
    if choice == "ylxf__removeequip" then
      local to = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets =tars,
        skill_name = _skill_val.name,
        prompt = "#steam__youlongxifeng-chooseget",
        cancelable = false,
      })[1]
      for _,id in ipairs(to:getCardIds("e")) do
        local card =Fk:getCardById(id)
        if card:getMark("steam__jiangjunchoujun")~=0 then
          room:moveCardTo(
            card,
            card.type == Card.TypeEquip and Player.Equip or Player.Judge,
            player,
            fk.ReasonPut,
            _skill_val.name,
            nil,
            true,
            player
          )
        end
      end
      
    elseif choice == "ylxf__removeskill" then
      
      local to = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets =tars,
        skill_name = _skill_val.name,
        prompt = "#steam__youlongxifeng-chooseget",
        cancelable = false,
      })[1]
      changeskill(room, target, false)
      changeskill(room, to, true)
    end
    local skill=Fk.skills["steam__kangkai"]---@type TriggerSkill
    if skill:isInstanceOf(TriggerSkill) then
        skill:use(nil, target, player, nil)
    end
  end
})

_skill_val:addEffect(fk.TargetConfirmed, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(_skill_val.name) and data.card.trueName == "slash" and player:distanceTo(target) <= 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:askToUseActiveSkill(player,{
      skill_name=_skill_val.name,
      extra_data={youlingxifeng_tos=target},
    })
  end,
})

_skill_val:addEffect(fk.TurnEnd, {
  anim_type = "negative",
  can_refresh = function (self, event, target, player, data)

   if player:hasSkill(_skill_val.name) and player:getMark("steam__jjcj-turn") > 0 then
    return true
   end
   return false
  end,
  on_refresh =function (self, event, target, player, data)
    local room=player.room
    local tos = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = room:getOtherPlayers(target, false),
      skill_name = _skill_val.name,
      prompt = "#steam__kangkai-useslash",
      cancelable = true,
    })
    if #tos> 0 then
      local to =tos[1]
      player.room:askToUseVirtualCard(to,{
        name="slash",
        cancelable=false,
      })
    end
  end
})

return _skill_val
